using System;
using System.Linq;
using System.Collections.Generic;
using System.Web.Security;
using SuperMarketManagement.DAO.NHibernate;
using SuperMarketManagement.Entity;

namespace SuperMarketManagement.Web.Security
{
    public class XRoleProvider : RoleProvider
    {
        public override bool IsUserInRole(string username, string roleName)
        {
            DAOFactory factory = new DAOFactory();
            Employee employee = factory.EmployeeDAO.GetByUsername(username);
            foreach (Role r in employee.Roles)
            {
                if (r.Name == roleName) return true;
            }
            return false;
        }

        public override string[] GetRolesForUser(string username)
        {
            DAOFactory factory = new DAOFactory();
            Employee employee = factory.EmployeeDAO.GetByUsername(username);
            return employee.Roles.Select(r => r.Name).ToArray();

        }

        public override void CreateRole(string roleName)
        {
            throw new NotImplementedException();
        }

        public override bool DeleteRole(string roleName, bool throwOnPopulatedRole)
        {
            throw new NotImplementedException();
        }

        public override bool RoleExists(string roleName)
        {
            throw new NotImplementedException();
        }

        public override void AddUsersToRoles(string[] usernames, string[] roleNames)
        {
            throw new NotImplementedException();
        }

        public override void RemoveUsersFromRoles(string[] usernames, string[] roleNames)
        {
            throw new NotImplementedException();
        }

        public override string[] GetUsersInRole(string roleName)
        {
            throw new NotImplementedException();
        }

        public override string[] GetAllRoles()
        {
            throw new NotImplementedException();
        }

        public override string[] FindUsersInRole(string roleName, string usernameToMatch)
        {
            throw new NotImplementedException();
        }

        public override string ApplicationName
        {
            get { throw new NotImplementedException(); }
            set { throw new NotImplementedException(); }
        }
    }
}